package cn.wen.bases.service.security;

import java.util.Date;
import java.util.Map;

import org.apache.log4j.Logger;

import cn.wen.bases.framework.spring.UtilsOfSpring;
import cn.wen.bases.pojo.security.User;
import cn.wen.java.utils.Assert;
import cn.wen.javax.security.AbstractUserFactory;
import cn.wen.javax.security.IUser;
import cn.wen.mybatis.IMyBatisDao;

/**
 * Title: 用户工厂（实现）
 * <p>
 * Description:
 * <p>
 * Copyright: Copyright (c) 2010-2012
 * 
 * @author <a href="mailto:ct_wen@qq.com">ctwen</a>, 温承瑭
 * @version Revision：1.0 Date：2012/3/22 Description：初完成。
 *          <P>
 */
public class UserFactory extends AbstractUserFactory<User> {

    private final Logger log = Logger.getLogger(getClass());

    private UserFactory() {
	super();
    }

    private static UserFactory userFactory;

    public static final UserFactory getInstance() {
	if (null == userFactory) userFactory = new UserFactory();
	return userFactory;
    }
    
    public User query(IUser user){
	Assert.isTrue(null != user.getLoginId(), "用户ID不能为空！");
	IMyBatisDao dao = UtilsOfSpring.getBean("myBatisDao", IMyBatisDao.class);
	Map<String, ?> um = (Map<String, ?>) dao.selectOne("cn.wen.xframe.security.select_User", user);
	return mapToUser(um);
    }

    @Override
    public User mapToUser(Map<String, ?> um) {
	if (null == um) return null; 
	User user = super.mapToUser(um);
	user.setMobilePhone((String) um.get("MOBILE_PHONE"));
	return user;
    }

}
